package com.jsmtr.rms.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.jsmtr.rms.service.IUtilService;

@Controller
@RequestMapping("/Do/AssignPosition")
public class DoAssignPositionController {
    @Resource
    private IUtilService utilService;

    //[start] 岗位列表

    @RequestMapping("/index")
    public String room() {
        return "/Do/AssignPosition/index";
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/getjobs")
    public void getjobs(HttpServletRequest request, HttpServletResponse response) {
        try {
			int perpage = Integer.parseInt(request.getParameter("perpage"));
			int page = Integer.parseInt(request.getParameter("page"));
			Map<String, Object> map = utilService.getJobs(page, perpage, request.getParameter("deptname"), request.getParameter("jobname"));
            StringBuilder result = new StringBuilder();
            double pageCount =(Double)map.get("pageCount");
            double allcount = (Double) map.get("count");
            if(pageCount!=0){
	            Object object = map.get("list");
	            int num=0;
	            for(Object[] _job : (List<Object[]>)object)
	            {
					result.append("<tr><td>" + (perpage * (page - 1) + num + 1) + "</td>");
					result.append("<td>" + _job[2] + "</td>");
					result.append("<td>" + _job[0] + "</td>");
					result.append("<td class='link'><input type='hidden' value='"+_job[1]+"'/><a href='javascript:'>选择</a></td></tr>");
	                num++;
	            }
            }else {
            	result.append("<tr><td colspan='4'>无符合条件的信息</td></tr>");
			}
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='4'>读取信息失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }
    }
    //[end]

}
